package com.ktgj.customer.service.impl;

import java.util.List;

import cn.hutool.core.date.DateUtil;
import com.ktgj.common.core.utils.DateUtils;
import com.ktgj.customer.domain.EmployeeVipresource;
import com.ktgj.customer.mapper.EmployeeVipresourceMapper;
import org.aspectj.apache.bcel.generic.RET;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.customer.mapper.EmployeeReturnvisitMapper;
import com.ktgj.customer.domain.EmployeeReturnvisit;
import com.ktgj.customer.service.IEmployeeReturnvisitService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * VIP资源回访记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-09-20
 */
@Service
public class EmployeeReturnvisitServiceImpl implements IEmployeeReturnvisitService 
{
    @Autowired
    private EmployeeReturnvisitMapper employeeReturnvisitMapper;
    @Resource
    private EmployeeVipresourceMapper employeeVipresourceMapper;

    /**
     * 查询VIP资源回访记录
     * 
     * @param returnVisitId VIP资源回访记录ID
     * @return VIP资源回访记录
     */
    @Override
    public EmployeeReturnvisit selectEmployeeReturnvisitById(Long returnVisitId)
    {
        return employeeReturnvisitMapper.selectEmployeeReturnvisitById(returnVisitId);
    }

    /**
     * 查询VIP资源回访记录列表
     * 
     * @param employeeReturnvisit VIP资源回访记录
     * @return VIP资源回访记录
     */
    @Override
    public List<EmployeeReturnvisit> selectEmployeeReturnvisitList(EmployeeReturnvisit employeeReturnvisit)
    {
        return employeeReturnvisitMapper.selectEmployeeReturnvisitList(employeeReturnvisit);
    }

    /**
     * 新增VIP资源回访记录
     * 
     * @param employeeReturnvisit VIP资源回访记录
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertEmployeeReturnvisit(EmployeeReturnvisit employeeReturnvisit)
    {
        int result = employeeReturnvisitMapper.insertEmployeeReturnvisit(employeeReturnvisit);
        if (result > 0)
        {
            Long vipResourceId = employeeReturnvisit.getVipresourceId();
            EmployeeVipresource vipResource = employeeVipresourceMapper.selectEmployeeVipresourceById(vipResourceId);
            vipResource.setVisitTime(DateUtils.getNowDate());
            employeeVipresourceMapper.updateEmployeeVipresource(vipResource);
        }
        return result;
    }

    /**
     * 修改VIP资源回访记录
     * 
     * @param employeeReturnvisit VIP资源回访记录
     * @return 结果
     */
    @Override
    public int updateEmployeeReturnvisit(EmployeeReturnvisit employeeReturnvisit)
    {
        return employeeReturnvisitMapper.updateEmployeeReturnvisit(employeeReturnvisit);
    }

    /**
     * 批量删除VIP资源回访记录
     * 
     * @param returnVisitIds 需要删除的VIP资源回访记录ID
     * @return 结果
     */
    @Override
    public int deleteEmployeeReturnvisitByIds(Long[] returnVisitIds)
    {
        return employeeReturnvisitMapper.deleteEmployeeReturnvisitByIds(returnVisitIds);
    }

    /**
     * 删除VIP资源回访记录信息
     * 
     * @param returnVisitId VIP资源回访记录ID
     * @return 结果
     */
    @Override
    public int deleteEmployeeReturnvisitById(Long returnVisitId)
    {
        return employeeReturnvisitMapper.deleteEmployeeReturnvisitById(returnVisitId);
    }
}
